package com.lyq.mr.speak;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SpeakReducer extends Reducer<Text,SpeakBean,Text,SpeakBean> {

    Text t =new Text();

    @Override
    protected void reduce(Text key, Iterable<SpeakBean> values, Context context) throws IOException, InterruptedException {
        Long selfDurations = 0l;
        Long thirdPartDurations =0l;
        for (SpeakBean speakBean : values) {
            selfDurations +=speakBean.getSelfDuration();
            thirdPartDurations +=speakBean.getThirdPartDuration();

        }
        SpeakBean speakBean = new SpeakBean(selfDurations,thirdPartDurations,key.toString());
        context.write(key,speakBean);
    }
}
